import { useRef } from "react";
import ChildCom from "./ChildCom.jsx";
export default () => {
  const cRef = useRef(null);
  const handleClick = () => {
    alert(1);
    if (cRef.current) {
      const result = cRef.current.getData();
      cRef.current.otherFun();
      alert(result);
    }
  };
  return (
    <div>
      <h3>父组件调用子组件</h3>
      <div>
        <ChildCom ref={cRef} />
        <button onClick={handleClick}>调用子组件</button>
      </div>
    </div>
  );
};
